package com.umer.pinban.adapter.customer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.common.image.bean.ImageInfo;
import com.common.ui.recycleview.adapter.RecyclerviewBasicAdapter;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.OptListener;
import com.common.utils.Constants;
import com.common.utils.GlideUtils;
import com.umer.pinban.R;
import com.umer.pinban.bean.PicInfosBean;
import com.umer.pinban.bean.customer.CustomerTailRecordBean;
import java.util.List;

public class CustomerRecordListPicAdapter extends RecyclerviewBasicAdapter<CustomerTailRecordBean.PicListBean> {

    private int height;
    private Context context;
    private OptListener optListener;
    private List<ImageInfo> imageInfoList;

    @SuppressLint("CheckResult")
    public CustomerRecordListPicAdapter(Context context, List<CustomerTailRecordBean.PicListBean> datas,
                                        int layoutId, int height, OptListener optListener,List<ImageInfo> imageInfoList) {
        super(context, datas, layoutId);
        this.context = context;
        this.height = height;
        this.optListener = optListener;
        this.imageInfoList = imageInfoList;
    }

    @Override
    public void convert(ViewHolder holder, final CustomerTailRecordBean.PicListBean pic, int position) {
        //SimpleDraweeView simpleDraweeView =  holder.getView(R.id.simpleDraweeView);
        ImageView iv = holder.getView(R.id.iv);
       /* LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) simpleDraweeView.getLayoutParams();
        linearParams.height = height;
        simpleDraweeView.setLayoutParams(linearParams);
        String filePath = pic.getFilePath();
        if(!TextUtils.isEmpty(filePath)){
            //Uri uri = Uri.parse(Constants.IP_PORT_DEFAULT_PICTURE + filePath);
            Uri uri = Uri.parse("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1594815416684&di=e80cdd7b5e4c1bdd06c25af9eee25e80&imgtype=0&src=http%3A%2F%2Fimg01.jituwang.com%2F170508%2F256960-1F50Q02K333.jpg");
            simpleDraweeView.setImageURI(uri);
        }else {
            Uri uri = Uri.parse("");
            simpleDraweeView.setImageURI(uri);
        }
        simpleDraweeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,Constants.IP_PORT_DEFAULT_PICTURE + pic.getFilePath());
            }
        });*/
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) iv.getLayoutParams();
        linearParams.height = height;
        iv.setLayoutParams(linearParams);
        GlideUtils.getInstance().loadImageView(context,
                Constants.IP_PORT_DEFAULT_PICTURE + pic.getFilePath(),
                iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PicInfosBean picInfosBean = new PicInfosBean();
                picInfosBean.setImageInfoList(imageInfoList);
                picInfosBean.setIndex(position);
                optListener.onOptClick(v,picInfosBean);
            }
        });

    }
}
